#{extends 'main.html' /}
#{set title:'Update Course' /}

<h1> Update Course </h1>

<form id ="form" action="@{Application.updateCourse()}" method="POST">
    Select a course <select size="1" name="course_id" id = "cid" onchange="this.form.submit()"> 
                <option value="">--</option>
            #{list items:models.Course.findAll(), as:'cr'}
                #{if cr.id == course_id}
                <option selected="selected" value="${cr.id}">${cr.name}</option>
                #{/if}
                #{else}
                 <option value="${cr.id}">${cr.name}</option>
                #{/else}
            #{/list}
           </select> 

</form>
<br>

#{if course_id != null}
<form id ="form" action="@{Application.updateCourse()}" method="POST">
    <input type="hidden" name="course_id" id="c_id"/>
    <script>
    $("#c_id").val(''+($("#cid").val()));
    </script>
    
    <table border="0">
    <tbody>
    <tr><td>Name</td> 
    <td><input type="text" name="name" value="${c.name}" required ="required"/>*</td>
    </tr>
    <tr><td>Description </td><td><textarea rows=5 cols=25 name="description" required ="required">${c.description}</textarea>*</td></tr>
    <tr><td>Price </td><td> <input type="text" name="price" value="${c.price}" required ="required"/> For Basic : per class , For Trinity : per package </td></tr>
    <tr><td>Level</td>
    <td> <input type="text" name="level" value="${c.level}" required ="required"/>	
    </td></tr>
    <tr><td>Type </td>
    <td><select size="1" name="type" required ="required"> 
    		#{if c.type.equals("Basic")}
    		<option value="1" selected="selected">Basic</option>
    		<option value="2">Trinity</option>
    		#{/if}
    		#{else}
    		<option value="1">Basic</option>
    		<option value="2" selected="selected">Trinity</option>
    		#{/else}
    	</select> </td></tr>
    
    <tr><td>Activity</td>
    <td><select size="1" name="activity_id" id = "s_id" required="required"> 
                <option value="">--</option>
            #{list items:models.Activity.findAll(), as:'a'}
                #{if a.id == c.activity.id}
                <option value="${a.id}" selected="selected">${a.name}</option>
                #{/if}
                #{else}
                <option value="${a.id}">${a.name}</option>
                #{/else}
                #{/list}
           </select>
    <tr><td>Code </td><td><input type="text" value="${c.code}" disabled="disabled"/></td></tr>
    </tbody>
    </table>
    <br>
    <input type="submit" value="Update"/>
    
    
</form>

#{/if}   

   
    